﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using WickedFlame.Core.Shapes;

namespace WickedFlame.Core.Layers
{
    public class BottomLayer : Layer
    {
        public BottomLayer()
            : base()
        {
            gridLines = new List<VectorShape>();
        }

        bool _isGridVisible = false;
        public bool IsGridVisible
        {
            get
            {
                return _isGridVisible;
            }
            set
            {
                _isGridVisible = value;

                if (_isGridVisible)
                    ShowGrid();
                else
                    HideGrid();
            }
        }

        List<VectorShape> gridLines;

        private void ShowGrid()
        {
            gridLines = new List<VectorShape>();

            int h = (int)(this.Height / 10);
            int w = (int)(this.Width / 10);

            for (int i = 0; i < h; i++)
                gridLines.Add(new LineShape
                {
                    StartPoint = new Point(0, i * 10),
                    EndPoint = new Point(Width, i * 10),
                    Stroke = Brushes.LightGray,// Beige,
                    StrokeThickness = 1
                });

            for (int i = 0; i < w; i++)
                gridLines.Add(new LineShape
                {
                    StartPoint = new Point(i * 10, 0),
                    EndPoint = new Point(i * 10, Height),
                    Stroke = Brushes.LightGray,// Beige,
                    StrokeThickness = 1
                });

            foreach (VectorShape shape in gridLines)
            {
                AddShape(shape);
                shape.Invalidate();
            }
        }

        private void HideGrid()
        {
            foreach (VectorShape shape in gridLines)
                RemoveShape(shape);

            gridLines.Clear();
        }
    }
}
